#include "DiolButton.h"

#include <assert.h>
#include <sstream>

namespace Diol
{
	
Button::Button( const ObjectInstance& objectInstance, Device* parentDevice )
  : Object( objectInstance, parentDevice ), 
	mIsPressed(false)
{
	assert( objectInstance.isButton() );		
}	

std::string Button::toString() const
{
	std::stringstream str;
	str << "Button Id:" << getObjectInstance().getDwType() << " Value:" << mIsPressed << " Name:'" << getObjectInstance().getName() << "'"; 
	return str.str();
}

void Button::updateFrom( const DIDEVICEOBJECTDATA& entry )
{
	bool isPressed = (entry.dwData & 0x80)!=0;
	setPressed( isPressed );
}

void Button::setPressed( bool isPressed )
{
	if ( isPressed==mIsPressed )
		return;
	mIsPressed = isPressed;
	notifyChanged();
}

}